

$(function () {

    $("#login").on("click", function () {
        const username = $("#username").val().trim();
        const password = $("#password").val().trim();
        if (!username || !password) {
            layer.open({
                title: '在线调试',
                content: '用户名或者密码不能为空',

            });
            return
        }
        $.ajax({
            url: "http://localhost:8080/api/v1/admin/user/login",
            type: "post",
            data: { username, password },
            success(res) {
                if (res.code === 200) {
                    // 使用了会话储存
                    sessionStorage.setItem("token", res.token)
                    //localStorage.setItem("token", res.token)//永久储存
                    console.log("登录成功");
                    location.href = "index.html"
                } else if (res.code === 400) {
                    layer.open({
                        title: '在线调试'
                        , content: res.msg
                    });
                }
            }
        })
    })
})